﻿using System;
using System.IO;

namespace PlusPlusPaint.FileIO
{
    /// <summary>
    /// Given a TextReader, returns the corresponding SerializedObject.
    /// </summary>
    /// <remarks>
    /// This could have been a single static function, but keeping it this way
    /// in case saving state will eventually be useful.
    /// </remarks>
    public class LayeredDataReader
    {
        #region member variables
        TextReader textreader;
        #endregion

        #region constructors
        public LayeredDataReader(TextReader tr)
        {
            if (tr == null)
                throw new Exception("TextReader may not be null!");
            textreader = tr;
        }
        #endregion

        #region public methods
        public SerializedObject Read()
        {
            string str = textreader.ReadToEnd();
            LayeredDataParser parser = new LayeredDataParser(str);
            return parser.Parse();
        }
        #endregion
    }
}
